package com.sample.weather3dwidget;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

    View clockView;
    Date date = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.CHINA);
    private Runnable mRefreshRunnable = new Runnable()
    {
        public void run()
        {
            MainActivity.this.rootView.postDelayed(this, 1000L);
            MainActivity.this.clockView.invalidate();
            MainActivity.this.date.setTime(System.currentTimeMillis());
            String str = MainActivity.this.dateFormat.format(new Date());
            MainActivity.this.timeView.setText(str);
        }
    };
    ScalpelFrameLayout rootView;
    TextView timeView;

    protected void onCreate(Bundle paramBundle)
    {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_main);
        this.rootView = ((ScalpelFrameLayout)findViewById(R.id.rootView));
        this.rootView.setLayerInteractionEnabled(true);
        this.rootView.setDrawViews(true);
        this.rootView.setChromeColor(0);
        this.rootView.setChromeShadowColor(-16777216);
        this.clockView = findViewById(R.id.clockView);
        this.timeView = ((TextView)findViewById(R.id.timeView));
        this.rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
        {
            public void onGlobalLayout()
            {
                MainActivity.this.rootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                MainActivity.this.runOnUiThread(MainActivity.this.mRefreshRunnable);
            }
        });
    }
}
